#!/usr/bin/python
"""
  (C) Copyright 2019-2021 Intel Corporation.

  SPDX-License-Identifier: BSD-2-Clause-Patent
"""
from command_utils_base import FormattedParameter
from command_utils import ExecutableCommand


class DaosPerfCommand(ExecutableCommand):
    """Defines a object representing the daos_perf command.

    The daos_perf utility benchmarks point-to-point I/O performance of different
    layers of the DAOS stack.
    """

    def __init__(self, path):
        """Create a daos_perf command object.

        Args:
            path (str): path to the daos_perf command
        """
        super().__init__(
            "/run/daos_perf/*", "daos_perf", path)

        # daos_perf command line options:
        #
        #   -P <number/string>
        #       Pool SCM partition size, which can have M(megatbytes) or
        #       G(gigabytes) as postfix of number. E.g. -P 512M, -P 8G.
        self.pool_scm_size = FormattedParameter("-P {}")

        #   -N <number/string>
        #       Pool NVMe partition size.
        self.pool_nvme_size = FormattedParameter("-N {}")

        #   -T <vos|echo|daos>
        #       Type of test, it can be 'vos' and 'daos'.
        #           vos  : run directly on top of Versioning Object Store (VOS).
        #           echo : I/O traffic generated by the utility only goes
        #               through the network stack and never lands to storage.
        #           daos : I/O traffic goes through the full DAOS stack,
        #               including both network and storage.
        #       The default value is 'vos'.
        self.test_type = FormattedParameter("-T {}", "vos")

        #   -C <number>
        #       Credits for concurrently asynchronous I/O. It can be value
        #       between 1 and 64. The utility runs in synchronous mode if
        #       credits is set to 0. This option is ignored for mode 'vos'.
        self.credits = FormattedParameter("-C {}")

        #   -c <TINY|LARGE|R2S|R3S|R4S|EC2P2|EC4P2|EC8P2>
        #       Object class for DAOS full stack test.
        self.object_class = FormattedParameter("-c {}")

        #   -o <number>
        #       Number of objects are used by the utility.
        self.objects = FormattedParameter("-o {}")

        #   -d <number/string>
        #       Number of dkeys per object. The number can have 'k' or 'm' as
        #       postfix which stands for kilo or million.
        self.dkeys = FormattedParameter("-d {}")

        #   -a <number/string>
        #       Number of akeys per dkey. The number can have 'k' or 'm' as
        #       postfix which stands for kilo or million.
        self.akeys = FormattedParameter("-a {}")

        #   -r <number/string>
        #       Number of records per akey. The number can have 'k' or 'm' as
        #       postfix which stands for kilo or million.
        self.records = FormattedParameter("-r {}")

        #   -A
        #       Use array value of akey, single value is selected by default.
        self.akey_use_array = FormattedParameter("-A", False)

        #   -s <number/string>
        #       Size of single value, or extent size of array value. The number
        #       can have 'K' or 'M' as postfix which stands for kilobyte or
        #       megabytes.
        self.value_size = FormattedParameter("-s {}")

        #   -z
        #       Use zero copy API, this option is only valid for 'vos'
        self.zero_copy_api = FormattedParameter("-z", False)

        #   -t
        #       Instead of using different indices and epochs, all I/Os land to
        #       the same extent in the same epoch. This option can reduce usage
        #       of storage space.
        self.same_extent = FormattedParameter("-t", False)

        #   -U
        #       Only run update performance test.
        self.update_test_only = FormattedParameter("-U", False)

        #   -F
        #       Only run fetch performance test. This does an update first, but
        #       only measures the time for the fetch portion.
        self.fetch_test_only = FormattedParameter("-F", False)

        #   -v
        #       Verify fetch. Checks that what was read from the filesystem is
        #       what was written to it. This verifcation is not part of timed
        #       performance measurement. This is turned off by default.
        self.verify_fetch = FormattedParameter("-v", False)

        #   -R
        #       Only run rebuild performance test.
        self.rebuild_test_only = FormattedParameter("-R", False)

        #   -B
        #       Profile performance of both update and fetch.
        self.profile_performance = FormattedParameter("-B", False)

        #   -I
        #       Only run iterate performance test. Only runs in vos mode.
        self.iterate_test_only = FormattedParameter("-I", False)

        #   -n
        #       Only run iterate performance test but with nesting iterator
        #       enable.  This can only run in vos mode.
        self.nesting_iterate_test_only = FormattedParameter("-n", False)

        #   -f <pathname>
        #       Full path name of the VOS file.
        self.pathname = FormattedParameter("-f {}")

        #   -w
        #       Pause after initialization for attaching debugger or analysis
        #       tool.
        self.pause_after_init = FormattedParameter("-w", False)

        # Environment variable names to export when running daos_perf
        self._env_names = ["D_LOG_FILE"]
